package com.bbs.services;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bbs.bean.BbsTitleInfo;
import com.bbs.dao.BbsTitleInfoDao;

@Transactional
@Service
public class BbsTitleInfoManager {
	private BbsTitleInfoDao bbsTitleInfoDao;

	public BbsTitleInfoDao getBbsTitleInfoDao() {
		return bbsTitleInfoDao;
	}

	public void setBbsTitleInfoDao(BbsTitleInfoDao bbsTitleInfoDao) {
		this.bbsTitleInfoDao = bbsTitleInfoDao;
	}
	
	public void save(BbsTitleInfo bbsTitleInfo){
		bbsTitleInfo.setTitleCreateTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		bbsTitleInfo.setTitleIstop(1);
		bbsTitleInfo.setTitleReplyNum(0);
		bbsTitleInfo.setTitleStatus(0);
		bbsTitleInfoDao.save(bbsTitleInfo);
	}
	
	public void update(BbsTitleInfo bbsTitleInfo){
		bbsTitleInfoDao.update(bbsTitleInfo);
	}
	
	public void delete(int id){
		bbsTitleInfoDao.deleteById(id);
	}
	
	public List<BbsTitleInfo> findAll(){
		return bbsTitleInfoDao.findAll();
	}

	public BbsTitleInfo findId(int id) {
		
		return bbsTitleInfoDao.getById(id);
	}

	public List<BbsTitleInfo> findAllByPage(int countPage) {
		
		return bbsTitleInfoDao.findAllByPage(countPage);
	}

	public int getCountInfo() {
		return bbsTitleInfoDao.getCountInfo();
	}
	
	public int getCountByBlockId(int pararmValue){
		return bbsTitleInfoDao.getCountByBlockId(pararmValue);
	}

	public List<BbsTitleInfo> findByBlock(Integer titleBlockid, int page) {
		return bbsTitleInfoDao.getByBlock(titleBlockid, page);
	}
}
